package com.jiangyao.controller;


import com.jiangyao.common.ApiResult;
import com.jiangyao.model.dto.backend.LecturerDTO;
import com.jiangyao.model.dto.backend.LecturerListPageDTO;
import com.jiangyao.model.entity.Lecturer;
import com.jiangyao.model.vo.backend.LecturerBaseVO;
import com.jiangyao.model.vo.backend.LecturerVO;
import com.jiangyao.service.LecturerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 讲师 前端控制器
 * </p>
 *
 * @author yangyongchuan
 * @since 2020-08-18
 */
@Api(tags = "讲师管理")
@RestController
@RequestMapping("/lecturer")
public class LecturerController extends BaseController {

	@Autowired
	private LecturerService lecturerService;

	/**
	 * 获取讲师列表
	 *
	 * @param listPageDTO 列表DTO
	 * @return 结果
	 */
	@ApiOperation(value = "获取讲师列表")
	@PostMapping("/list")
	public ApiResult<Lecturer> getListPage(@Validated({LecturerListPageDTO.ListPage.class}) @RequestBody LecturerListPageDTO listPageDTO) {
		return ApiResult.success(lecturerService.getListPage(listPageDTO));
	}

	/**
	 * 增加讲师
	 *
	 * @param lecturerDTO 增加DTO
	 * @return 结果
	 */
	@ApiOperation(value = "增加讲师")
	@PostMapping("/add")
	public ApiResult<String> add(@Validated({LecturerDTO.Add.class}) @RequestBody LecturerDTO lecturerDTO) {
		lecturerService.add(lecturerDTO);
		return new ApiResult<>("ok");
	}

	/**
	 * 编辑讲师
	 *
	 * @param lecturerDTO 编辑DTO
	 * @return 结果
	 */
	@ApiOperation(value = "编辑讲师")
	@PostMapping("/edit")
	public ApiResult<String> edit(@Validated({LecturerDTO.Edit.class}) @RequestBody LecturerDTO lecturerDTO) {
		lecturerService.edit(lecturerDTO);
		return new ApiResult<>("ok");
	}

	/**
	 * 获取讲师详情
	 *
	 * @param lecturerDTO 请求DTO
	 * @return 结果
	 */
	@ApiOperation(value = "获取讲师详情", notes = "必填字段：lecturerId")
	@PostMapping("/detail")
	public ApiResult<LecturerVO> detail(@Validated({LecturerDTO.Detail.class}) @RequestBody LecturerDTO lecturerDTO) {
		return new ApiResult<>(lecturerService.getDetail(lecturerDTO));
	}

	/**
	 * 编辑讲师状态（启用、禁用）
	 *
	 * @param lecturerDTO 编辑DTO
	 * @return 结果
	 */
	@ApiOperation(value = "编辑讲师状态（启用、禁用）", notes = "必填字段：lecturerId、status")
	@PostMapping("/editStatus")
	public ApiResult<String> editStatus(@Validated({LecturerDTO.Delete.class}) @RequestBody LecturerDTO lecturerDTO) {
		lecturerService.editStatus(lecturerDTO);
		return new ApiResult<>("ok");
	}

	/**
	 * 根据名称检索讲师（最多返回50）
	 *
	 * @param lecturerDTO DTO
	 * @return 结果
	 */
	@ApiOperation(value = "根据名称检索讲师（最多返回50）", notes = "选填字段：lecturerName")
	@PostMapping("/listForSelect")
	public ApiResult<LecturerBaseVO> listForSelect(@RequestBody LecturerDTO lecturerDTO) {
		return ApiResult.success(lecturerService.listForSelect(lecturerDTO), LecturerBaseVO.class);
	}
}

